package com.huluobo.a2109kotlinshopping.home

import androidx.lifecycle.MutableLiveData
import com.huluobo.a2109kotlinshopping.base.BaseRepo
import com.huluobo.a2109kotlinshopping.net.Const
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import retrofit2.http.Query

/**
 *  Created by LC on 2024/1/11.
 */
class HomeRepo : BaseRepo() {
    fun getHomeGoodsList(
        categoryId: Int,
        currentPage: Int,
        pageSize: Int,
        success: MutableLiveData<HomeGoodsBeanResult>,
        failed: MutableLiveData<String>
    ) {
        getService().getHomeGoodsList(categoryId, currentPage, pageSize)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<HomeGoodsBeanResult> {
                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                    failed.value = e.message
                }

                override fun onComplete() {
                }

                override fun onNext(t: HomeGoodsBeanResult) {
                    success.value = t
                }
            })
    }

    fun getHomeBanner(success: MutableLiveData<HomeBannerBeanResult>, failed: MutableLiveData<String>) {
        getService().getHomeBanner()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<HomeBannerBeanResult> {
                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                    failed.value = e.message
                }

                override fun onComplete() {
                }

                override fun onNext(t: HomeBannerBeanResult) {
                    success.value = t
                }
            })
    }

    fun getHomeNav(success: MutableLiveData<HomeNavBeanResult>, failed: MutableLiveData<String>) {
        getService().getHomeNav()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<HomeNavBeanResult> {
                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                    failed.value = e.message
                }

                override fun onComplete() {
                }

                override fun onNext(t: HomeNavBeanResult) {
                    success.value = t
                }
            })
    }
}